package ms.unicorn.diagram.figures.decorators;

import ms.unicorn.dsl.IFigureEx;
import ms.unicorn.dsl.ITheme;
import ms.unicorn.util.FigureUtil;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolylineDecoration;

public class OpenArrow extends PolylineDecoration {
	
	private IFigure parentEx = FigureUtil.NULL_FIGURE; 
	
	@Override
	public void paintFigure(Graphics graphics) {
		// update the line attribute according to parent theme
		IFigureEx parent = getParentEx();
		if (parent != null) {
			ITheme theme = parent.getTheme();
			setLineWidthFloat(theme.getLineWidth());
			setForegroundColor(theme.getForeColor());
			setBackgroundColor(theme.getBackgroundColor());
		}
		super.paintFigure(graphics);
	}
	
	private IFigureEx getParentEx() {
		if (parentEx == FigureUtil.NULL_FIGURE) {
			parentEx = FigureUtil.findParentFigureEx(this);
		}
		return (IFigureEx)parentEx;
	}
}
